//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.lanf.system.code;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.util.Iterator;
import java.util.Set;

public class JsonUtil {
    public JsonUtil() {
    }

    public static void convert(Object obj) {
        if (obj instanceof JSONArray) {
            JSONArray jsonArray = (JSONArray)obj;
            Iterator var2 = jsonArray.iterator();

            while(var2.hasNext()) {
                Object json = var2.next();
                convert(json);
            }
        } else if (obj instanceof JSONObject) {
            JSONObject json = (JSONObject)obj;
            Set<String> keySet = json.keySet();
            String[] keyArray = (String[])keySet.toArray(new String[keySet.size()]);
            String[] var4 = keyArray;
            int var5 = keyArray.length;

            for(int var6 = 0; var6 < var5; ++var6) {
                String key = var4[var6];
                Object value = json.get(key);
                String[] keyStrs = key.split("_");
                if (keyStrs.length > 1) {
                    StringBuilder sb = new StringBuilder();
                    int i = 0;

                    while(true) {
                        if (i >= keyStrs.length) {
                            json.remove(key);
                            json.put(sb.toString(), value);
                            break;
                        }

                        String keyStr = keyStrs[i];
                        if (!keyStr.isEmpty()) {
                            if (i == 0) {
                                sb.append(keyStr);
                            } else {
                                int c = keyStr.charAt(0);
                                if (c >= 'a' && c <= 'z') {
                                    int v = c - 32;
                                    sb.append((char)v);
                                    if (keyStr.length() > 1) {
                                        sb.append(keyStr.substring(1));
                                    }
                                } else {
                                    sb.append(keyStr);
                                }
                            }
                        }

                        ++i;
                    }
                }

                convert(value);
            }
        }

    }

    public static Object convertUnderlineToCamelCase(String str) {
        Object obj = JSON.parse(str);
        convert(obj);
        return obj;
    }

    public static void main(String[] args) {
        String json = "{\n  \"test\": [\n    {\n      \"self_auth\": {\n        \"a_id\": \"123\",\n        \"b_num\": 7,\n        \"user_name\": \"oldlu\"\n      }\n    }\n  ]\n}";
        String str = "" + convertUnderlineToCamelCase(json);
        System.out.println(str);
    }
}
